#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time       : 2025/8/6 8:27
# @Author     : cfg
# @File       : bean.py
# @Software   : PyCharm
# @Description: The description of this file.
import random

import pygame
import pygame.gfxdraw

from statics.color import Color


class Bean(pygame.sprite.Sprite):
    def __init__(self, x, y, color: tuple = Color.bean):
        pygame.sprite.Sprite.__init__(self)
        self.x = x
        self.y = y
        self.image = pygame.Surface((10, 10))
        self.radius = 5
        self.color = color
        self.rect = self.image.get_rect()
        self.rect.center = (x, y)

    def spawn(self, players, wall_list):
        x = random.randint(10, 790)
        y = random.randint(110, 590)
        self.rect.center = [x, y]

        player_header_rects = []
        for p in players:
            player_header_rects.append(p.header.rect)
        if self.rect.collidelist(wall_list) != -1 or self.rect.collidelist(player_header_rects) != -1:
            self.spawn(players, wall_list)

    def destroy(self):
        self.kill()


if __name__ == '__main__':
    b = Bean(1, 3)
    b.destroy()
